package org.muninn.niagara.structures;

import javax.baja.sys.BComponent;
import javax.baja.sys.BObject;

public class BPointTreeNode extends BObject
{
  public String name = "";
  protected BPointTreeNode[] children = new BPointTreeNode[64];
  protected BComponent realObj;
  
  public BPointTreeNode(BComponent comp)
  {
    this.name = comp.getName();
    this.realObj = comp;
  }
  
  public BPointTreeNode[] getChildren() { return children; }
  
  public BComponent getComponent() { return this.realObj; }
  
  public boolean isNull() { return (this.realObj == null); }
  
  public void add(BPointTreeNode node)
  {
    for (int i = 0; i < children.length; i++)
    {
      if (children[i] == null)
      {
        children[i] = node;
        return;
      }
    }
    
    BPointTreeNode[] temp = new BPointTreeNode[children.length * 2];
    for (int i = 0; i < children.length; i++)
      temp[i] = children[i];
    
    temp[children.length] = node;
    children = temp;
  }
  
  public void remove(BPointTreeNode node)
  {
    for (int i = 0; i < children.length; i++)
    {
      if (children[i].equals(node))
      {
        remove(i);
        return;
      }
    }
  }
  
  public void remove(int index) { children[index] = null; }
}
